Skip to content
This repository was archived by the owner on Sep 17, 2025. It is now read-only.

Metrics view data conversion#469

Merged
c24t merged 3 commits intocensus-instrumentation:masterfrom
c24t:metrics-viewdata-conversion
Jan 29, 2019
Merged

Metrics view data conversion#469
c24t merged 3 commits intocensus-instrumentation:masterfrom
c24t:metrics-viewdata-conversion

Conversation

@c24t
Copy link
Copy Markdown
Member

@c24t c24t commented Jan 25, 2019

This PR adds a utility function to convert ViewDatas into Metrics, following up on #467.

@mayurkale22 I'm sending this your way for early review. We could merge this change safely by itself, or extend it to include:

  • metric conversions in the view manager and measure-to-view map
  • metric producers

Edit: done:

  • cache metric descriptor on view data

Addresses #335.

for view_data in view_data_list:
if view_data.view.name == view_name:
view_data_copy = copy.deepcopy(view_data)
view_data_copy = copy.copy(view_data)
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@songy23 I'm assuming the deepcopy here was defensive, so the returned ViewData had a separate _tag_value_aggregation_data_map. But this is also creating new Views (and associated measures and aggregations) on each call, which I don't think you want.

Changing this to copy means that the "copies" returned here share the aggregation data map. A better solution might be to implement ViewData.__copy__ or come up with a new immutable view data obj for export.

Copy link
Copy Markdown
Contributor

@songy23 songy23 Jan 28, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm assuming the deepcopy here was defensive, so the returned ViewData had a separate _tag_value_aggregation_data_map.

That's correct.

Changing this to copy means that the "copies" returned here share the aggregation data map.

Ideally the ViewData returned should be immutable, i.e:

vd1 = stats.get_view("some view")  # vd1 has data 1.0
vd1.record(1.0) # vd1 now has data 2.0
vd2 = stats.get_view("some view") # vd2 should still have data 1.0

So at least the _tag_value_aggregation_data_map should be deeply copied.

A better solution might be to implement ViewData.copy or come up with a new immutable view data obj for export.

+1 for the latter (using immutable view data obj for export). This is exactly what we do in Java.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @songy23. I changed this to deep-copy the aggregation map only in 5ad48a3. MeasureToViewMap would benefit from a total rewrite.


# Cache the converted MetricDescriptor here to avoid creating it each
# time we convert a ViewData that realizes this View into a Metric.
self._md_cache_lock = threading.Lock()
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other stats classes are generally not threadsafe. I don't know that it's worth opening this can of worms in this PR.

@c24t c24t force-pushed the metrics-viewdata-conversion branch from 601146f to c8db0ad Compare January 28, 2019 21:39
@c24t c24t force-pushed the metrics-viewdata-conversion branch from c8db0ad to e9e0d39 Compare January 28, 2019 22:26
if view_data.view.name == view_name:
break
else:
return None
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I rewrote this for clarity, the only behavior change is the copy below. Note that we're not using timestamp here, there are likely other bugs hiding in this class.

@c24t c24t merged commit ad778ff into census-instrumentation:master Jan 29, 2019
@c24t c24t deleted the metrics-viewdata-conversion branch January 29, 2019 00:18
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants